package com.milo.thread.threadlocal;

import com.alibaba.fastjson.JSONObject;

/**
 * <p>
 *     测试ThreadLocal的相关api
 * </p>
 * @author Milo Lee
 * @date 2021-04-21 09:19
 */
public class ThreadLocalTest {

    private static ThreadLocal<User> threadLocal = ThreadLocal.withInitial(()->new User("milolee",12));

    public static void main(String[] args) {
        //threadLocal.set(new User("milo",11));
        User user = threadLocal.get();
        System.out.println(JSONObject.toJSONString(user));
    }

    static class User{
        public String name;
        public int age;

        public User(String name,int age){
            this.name = name;
            this.age = age ;
        }

    }

}
